/*
 * File: MessageSetter.java Author: Robert Bittle <guywithnose@gmail.com>
 */
package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import faceBook.*;

/**
 * The Class MessageSetter.
 */
public class Options extends AuthenticationServlet
{

  /*
   * (non-Javadoc)
   * 
   * @see
   * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
   * javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException
  {
    if (req.getParameter("userid") == null
        || req.getParameter("accessToken") == null
        || !authenticate(Long.valueOf(req.getParameter("userid")),
            req.getParameter("accessToken")))
    {
      resp.getWriter().write(errorJson("Authentication failed."));
      return;
    }
    long userid = Long.valueOf(req.getParameter("userid"));

    User user = new User(userid);

    if (req.getParameter("useReply") != null)
    {
      user.setUseReply(Boolean.valueOf(req.getParameter("useReply")));
    }

    if (req.getParameter("useDefaultBD") != null)
    {
      user.setUseDefaultBD(Boolean.valueOf(req.getParameter("useDefaultBD")));
    }

    if (req.getParameter("defaultBDMessageMale") != null)
    {
      user.setDefaultBDMessageMale(req.getParameter("defaultBDMessageMale"));
    }

    if (req.getParameter("defaultBDMessageFemale") != null)
    {
      user.setDefaultBDMessageFemale(req.getParameter("defaultBDMessageFemale"));
    }

    if (req.getParameter("replyMessage") != null)
    {
      user.setReplyMessage(req.getParameter("replyMessage"));
    }
    
    user.save();

    resp.getWriter().write(successJson());

  }

}